//
//  QQMainChatWindow.m
//  MacDevTest
//
//  Created by lbxia on 2020/8/15.
//  Copyright © 2020 com.lbx. All rights reserved.
//

#import "QQMainChatWindow.h"
#import <Masonry/Masonry.h>
#import "QQChatViewController.h"
#import "QQChatSplitViewController.h"
#import "QQFriendsManage.h"
#import "QQApplicationViewController.h"

@interface QQMainChatWindow ()<QQFriendsManageDelegate>
//@property (nonatomic, strong) QQChatViewController *chatVC;

@property (nonatomic, strong) QQChatSplitViewController *chatVC;
@property (nonatomic, strong) QQFriendsManage *friendVC;
@property (nonatomic, strong) QQApplicationViewController *appcationVC;
@property (weak) IBOutlet NSButton *chatBtn;
@property (weak) IBOutlet NSButton *friendBtn;
@property (weak) IBOutlet NSButton *applicationBtn;

@end

@implementation QQMainChatWindow

- (void)windowDidLoad {
    [super windowDidLoad];
    
    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    
    [self.window center];
    
    
    //限制最小大小
//    self.chatVC = [[QQChatViewController alloc]initWithNibName:@"QQChatViewController" bundle:[NSBundle mainBundle]];
    
    self.chatVC = [[QQChatSplitViewController alloc]initWithNibName:@"QQChatSplitViewController" bundle:[NSBundle mainBundle]];
    
    
    [self.window.contentView addSubview:self.chatVC.view];
    [self.chatVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.window.contentView);
        make.top.equalTo(self.chatBtn.mas_bottom).offset(10);
    }];
   
}

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize
{
    NSSize size = frameSize;
    if (size.width < 600) {
        size.width = 600;
    }
    
    if (size.height < 500)
    {
        size.height = 500;
    }
    
    return size;
}

- (void)restBtnImages
{
    [self.chatBtn setImage:[NSImage imageNamed:@"menu-message-normal"]];
    [self.friendBtn setImage:[NSImage imageNamed:@"menu-contact-normal"]];
    [self.applicationBtn setImage:[NSImage imageNamed:@"menu-more-normal"]];

    //menu-message-normal
//    menu-message-down
    
    //menu-contact-normal
    //menu-contact-down
    
    //menu-more-normal
    //menu-more-down
    
    
}

- (IBAction)showChatVC:(id)sender {
    
    [self restBtnImages];
    
    if (_friendVC) {
        _friendVC.view.hidden = YES;
    }
    if (_appcationVC) {
        _appcationVC.view.hidden = YES;
    }
    
    _chatVC.view.hidden = NO;
    
    [self.chatBtn setImage:[NSImage imageNamed:@"menu-message-down"]];
}

- (IBAction)showFriendVC:(id)sender {

    [self restBtnImages];
    _chatVC.view.hidden = YES;
    
    if (_appcationVC) {
        _appcationVC.view.hidden = YES;
    }
    
    if (!_friendVC) {
        self.friendVC = [[QQFriendsManage alloc]initWithNibName:@"QQFriendsManage" bundle:[NSBundle mainBundle]];
        self.friendVC.delegate = self;
        [self.window.contentView addSubview:self.friendVC.view];
        [self.friendVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.window.contentView);
            make.top.equalTo(self.chatBtn.mas_bottom).offset(10);
        }];
    }
    
    _friendVC.view.hidden = NO;
    
    [self.friendBtn setImage:[NSImage imageNamed:@"menu-contact-down"]];
}

- (void)didAddFriendWithId:(NSString*)friendID friendNickName:(NSString*)nickName
{
    [self showChatVC:nil];
    
    [self.chatVC addfriend];
}


- (IBAction)showApplicationVC:(id)sender {
    
    [self restBtnImages];
    
    if (_friendVC) {
        _friendVC.view.hidden = YES;
    }
    
    _chatVC.view.hidden = YES;
    
  
    if (!_appcationVC) {
        
        self.appcationVC = [[QQApplicationViewController alloc]initWithNibName:@"QQApplicationViewController" bundle:[NSBundle mainBundle]];
        [self.window.contentView addSubview:self.appcationVC.view];
        [self.appcationVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.window.contentView);
            make.top.equalTo(self.chatBtn.mas_bottom).offset(10);
        }];
    }
    
    _appcationVC.view.hidden = NO;
    
    [self.applicationBtn setImage:[NSImage imageNamed:@"menu-more-down"]];
}

@end
